package com.example.day09_7_9_2.util;

import java.io.File;
import java.io.IOException;

import okhttp3.Cache;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

public class HttpUtil {
    private static volatile HttpUtil httpUtil = null;
    private HttpUtil(){
        initOkHttp();
    }

    private void initOkHttp() {
//        Cache cache = new Cache(new File(Constants.PATH));
        new OkHttpClient.Builder()
                .addNetworkInterceptor(new LogInterceptor());
//                .cache(cache);

    }

    public static HttpUtil getInstance(){
        if (httpUtil == null){
            synchronized (HttpUtil.class){
                if (httpUtil == null){
                    httpUtil = new HttpUtil();
                }
            }
        }
        return httpUtil;
    }
    class LogInterceptor implements Interceptor{

        @Override
        public Response intercept(Chain chain) throws IOException {
            Request request = chain.request();
            Response proceed = chain.proceed(request);
            LogUtil.logD("111",proceed.peekBody(1024*1024).string())  ;
            return proceed;
        }
    }
}
